layui.use(function () {
    var carousel = layui.carousel;
    // 渲染 - 图片轮播
    carousel.render({
        elem: '#ID-carousel-demo-image',
        width: '100%', // 设置为百分比适配主页面的宽度
        height: '340px',
        interval: 3000
    });
});

// 在页面加载完成后绑定按钮事件
document.addEventListener("DOMContentLoaded", function () {
    // 绑定功能卡片按钮的点击事件
    const buttons = document.querySelectorAll(".assessment-card button");

    buttons.forEach(button => {
        button.addEventListener("click", handleButtonClick);
    });
});

function handleButtonClick(event) {
    // 获取点击的按钮并根据内容执行对应操作
    const buttonText = event.target.textContent;

    if (buttonText.includes("算法挑战")) {
        startAlgorithmChallenge();
    } else if (buttonText.includes("编程语言测试")) {
        startLanguageTest();
    } else if (buttonText.includes("数据结构训练")) {
        startDataStructureTraining();
    } else if (buttonText.includes("项目实战")) {
        startProjectPractices();
    }
}

// 各个功能卡片按钮对应的函数
function startAlgorithmChallenge() {
    // 跳转到算法挑战页面
    window.location.href = "/html/sub-practice/algorithm_challenge.html";
}

function startLanguageTest() {
    // 跳转到编程语言测试页面
    window.location.href = "/html/sub-practice/language_test.html";
}

function startDataStructureTraining() {
    // 跳转到数据结构训练页面
    window.location.href = "/html/sub-practice/data_structure_training.html";
}

function startProjectPractices() {
    // 跳转到项目实战页面
    window.location.href = "/html/sub-practice/project_practices.html";
}
